<%-- 
    Document   : ListOfProducts
    Created on : Apr 26, 2013, 11:07:39 PM
    Author     : Gleb
--%>

<%@page import="com.charlie.beans.Product"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.util.List"%>

<%@include file="/header.jsp" %>

<div class="left_side">
    <jsp:include page="/blocks/conditionalLeftBar.jsp" />
</div>

<div class="right_side"> 
    <h2 class="content_title">List of products: </h2>
    <div class="white_block" >
        <table align="center" border="0">
            <tr>
                <td colspan="5">
                    <span style ="margin-left: 2px;">ID</span> 
                    <span style ="margin-left: 190px;">NAME</span> 
                    <span style ="float: right; margin-right: 140px;">COST</span>
                    <hr>
                </td>
            </tr>

                <%
                List<Product> products = (List<Product>) request.getAttribute("productList");
                boolean showAdd = request.getParameter("add") != null;
                if (products != null) {
                    for (Product product : products) {
                %>
                        <tr>
                            <td width = "5%"><%= product.getProductId() %></td>
                            <td width = "70%"><%= product.getName() %></td>
                            <td width = "10%"><%= product.getCost() %></td>
                <%      if (showAdd) { %>
                            <td width = "5%">
                                <form method="post" action="${pageContext.request.contextPath}/warehouse/order">
                                    <input type="hidden" name="id" value="<%= product.getProductId() %>">
                                           <input type="submit" value="Add">
                                </form>
                            </td>
                <%      } else { %>
                            <td width = "5%">
                                <form method="post" action = "editProductServlet">
                                    <input type="hidden" name="id" value="<%= product.getProductId() %>">
                                    <input type="submit" value="Edit">
                                </form>
                            </td>
                            <td width = "10%">
                                <form method="post" action = "DeleteProduct">
                                    <input type="hidden" name="id" value="<%= product.getProductId() %>">
                                    <input type="submit" value="Delete">
                                </form>
                            </td>
                <%      }
                        out.print("</tr>");
                    }
                }
                %>
            </table>       
    </div>
    <jsp:include page="/blocks/pages.jsp">
        <jsp:param name="path" value="warehouse/products" />
    </jsp:include>
</div>
<%@include file="/footer.jsp" %>